package com.zk.wx.menager;

import com.zk.wx.model.commons.Token;
import com.zk.wx.model.menu.Button;
import com.zk.wx.model.menu.CommonButton;
import com.zk.wx.model.menu.Menu;
import com.zk.wx.util.WxUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 个人未认证无自定义菜单权限
 *
 */
public class MenuManager {
    private static Logger log = LoggerFactory.getLogger(MenuManager.class);
    public static void main(String[] args) {
        // 第三方用户唯一凭证
        String appId = "wx878506f0b1ad8282";
        // 第三方用户唯一凭证密钥
        String appSecret = "1b346a7e7313eda277ecebf4988c4ad9";

        // 调用接口获取access_token
        Token at = WxUtil.getAccessToken(appId, appSecret);

        if (null != at) {
            // 调用接口创建菜单
            int result = WxUtil.createMenu(getMenu(), at.getAccessToken());

            // 判断菜单创建结果
            if (0 == result)
                log.info("菜单创建成功！");
            else
                log.info("菜单创建失败，错误码：" + result);
        }
    }
    /**
     * 组装菜单数据
     *
     * @return
     */
    private static Menu getMenu() {
        CommonButton btn11 = new CommonButton();
        btn11.setName("屁屁影院");
        btn11.setType("click");
        btn11.setKey("1");

        /**
         * 封装整个菜单
         */
        Menu menu = new Menu();
        menu.setButton(new Button[] { btn11});

        return menu;
    }
}
